package com.wxapp.admin.service.controller;

import com.wxapp.admin.api.pojo.vm.dept.PDeptDetailVm;
import com.wxapp.admin.api.pojo.vm.dept.PDeptTreeVm;
import com.wxapp.admin.api.pojo.vo.dept.QDeptSaveVo;
import com.wxapp.admin.api.pojo.vo.dept.QDeptTreeVo;
import com.wxapp.admin.api.pojo.vo.dept.QDeptUpdateVo;
import com.wxapp.admin.service.service.DeptService;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 部门
 * @Datetime 2022/8/6 17:10
 * @Modified By
 */

@RestController
@RequestMapping("/dept")
@Tag(name = "部门管理")
@RequiredArgsConstructor
public class DeptController extends IBaseController {
    private final  DeptService deptService;

    @PostMapping("/save")
    @Operation(summary ="保存部门信息")
    public ResultVm<String> saveDept(@Schema(hidden = true) @User UserVo userVo, @RequestBody QDeptSaveVo qDeptSaveVo) {
        return deptService.saveDept(userVo, qDeptSaveVo);
    }

    @PutMapping("/update")
    @Operation(summary ="更新部门信息")
    public ResultVm<String> updateDept(@Schema(hidden = true) @User UserVo userVo, @RequestBody QDeptUpdateVo qSaveVo) {
        return deptService.updateDept(userVo, qSaveVo);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary ="得到部门详情")
    public ResultVm<PDeptDetailVm> detailDept(@PathVariable String id) {
        return deptService.detailDept(id);
    }

    @PostMapping("/tree")
    @Operation(summary ="部门列表")
    public ResultVm<List<PDeptTreeVm>> treeDept(@RequestBody QDeptTreeVo qSaveVo) {
        return deptService.treeDept(qSaveVo);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary ="删除部门")
    public ResultVm<String> deleteDept(@PathVariable String id) {
        return deptService.deleteDept(id);
    }

    @GetMapping("/list")
    @Operation(summary ="得到部门详情")
    public ResultVm<PDeptDetailVm> listDept(@RequestParam String id) {
        return deptService.detailDept(id);
    }
}
